package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"gopkg.in/ini.v1"
	"net/http"
)

var config, _ = ini.Load("./config/app.ini")

// getConfig
// @Description: 获取配置
// @param section string
// @param key string
// @return *ini.Key
func getConfig(section, key string) *ini.Key {
	return config.Section(section).Key(key)
}

func main() {
	mode := getConfig("server", "env").String()
	if mode != gin.ReleaseMode {
		mode = gin.DebugMode
	}
	gin.SetMode(mode)

	r := gin.Default()
	r.GET("/", func(ctx *gin.Context) {
		ctx.JSON(http.StatusOK, gin.H{
			"code":    0,
			"message": "ok",
			"data":    nil,
		})
	})

	addr, err := getConfig("server", "port").Int()
	if err != nil {
		panic(err)
	}

	fmt.Printf("server start success at :%d ...\n", addr)
	if err = r.Run(fmt.Sprintf(":%d", addr)); err != nil {
		panic(err)
	}
}
